package demo1;

import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-06-30
 * Time: 16:26
 */

class Student {
}
public class Test01 {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abcde");
        StringBuilder str = stringBuilder.append("abcde");
        System.out.println(str);
    }
    public static void main14(String[] args) {
        String s1 = new String("abc");
    }
    public static void main13(String[] args) {
        String s1 = "    abc abc abc    ";
        System.out.println(s1.trim());//abc abc abc
    }
    public static void main12(String[] args) {
        String s1 = "abcdefgh";
        System.out.println(s1.substring(2));//cdefgh
        System.out.println(s1.substring(2,5));//cde
    }
    public static void main11(String[] args) {
        String s1 = "abc&abc&abc";
        String[] arr = s1.split("&");
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        String s2 = "abc.abc.abc";
        String[] arr2 = s2.split("\\.");
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
        String s3 = "abc\\abc\\abc";
        String[] arr3 = s3.split("\\\\");
        for (int i = 0; i < arr3.length; i++) {
            System.out.println(arr3[i]);
        }
        String s4 = "abcd&abcd#abcd";
        String[] arr4 = s4.split("&|#");
        for (int i = 0; i < arr4.length; i++) {
            System.out.println(arr4[i]);
        }
        String str = "hello world hello bit" ;
        String[] result = str.split(" ",3) ;
        for(String s: result) {
            System.out.println(s);
        }
    }
    public static void main10(String[] args) {
        String s1 = "abcabbccbaabc";
        String tmp1 = s1.replace('a','h');
        System.out.println(tmp1);//hbchbbccbhhbc
        String tmp2 = s1.replace("ab","hhhhh");
        System.out.println(tmp2);//hhhhhchhhhhbccbahhhhhc
        String tmp3 = s1.replaceAll("ab","hhhhh");
        System.out.println(tmp3);//hhhhhchhhhhbccbahhhhhc
        String tmp4 = s1.replaceFirst("ab","hhhhh");
        System.out.println(tmp4);//hhhhhcabbccbaabc
    }
    public static void main9(String[] args) {
        String s1 = "hello";
        //字符串转数组
        char[] arr = s1.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        //数组转字符串
        char[] arr2 = {'h','e','l','l','o'};
        String s2 = new String(arr2);
        System.out.println(s2);

        String s3 = String.format("%d-%d-%d",2025,5,5);
        System.out.println(s3);//2025-5-5
    }
    public static void main8(String[] args) {
        String s1 = "abc";
        String s2 = "ABC";
        //小写转大写
        System.out.println(s1.toUpperCase());
        //大写转小写
        System.out.println(s2.toLowerCase());
    }
    public static void main7(String[] args) {
        String s1 = String.valueOf(123);
        String s2 = String.valueOf(1.23);
        String s3 = String.valueOf(true);
        String s4 = String.valueOf(new Student());
        System.out.println(s1);//123
        System.out.println(s2);//1.23
        System.out.println(s3);//true
        System.out.println(s4);//demo1.Student@41629346
        int a1 = Integer.parseInt("123");
        Double a2 = Double.parseDouble("3.14");
    }
    public static void main6(String[] args) {
        String s1 = "abcdefgabcd";
        int a1 = s1.lastIndexOf('d');
        System.out.println(a1);//10
        int a2 = s1.lastIndexOf('d',5);
        System.out.println(a2);//3
        int a3 = s1.lastIndexOf("abc");
        System.out.println(a3);//7
        int a4 = s1.lastIndexOf("abc",5);
        System.out.println(a4);//0
    }
    public static void main5(String[] args) {
        String s1 = "abcdefgabcd";
        char c1 = s1.charAt(2);
        System.out.println(c1);//c
        int a1 = s1.indexOf('d');
        System.out.println(a1);//3
        int a2 = s1.indexOf('d',5);
        System.out.println(a2);//10
        int a3 = s1.indexOf("abc");
        System.out.println(a3);//0
        int a4 = s1.indexOf("abc",5);
        System.out.println(a4);//7
    }
    public static void main4(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("HELLO");
        System.out.println(s1.compareTo(s2));//32
        System.out.println(s1.compareToIgnoreCase(s2));//0
    }
    public static void main3(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("helloworld");
        String s3 = new String("abcdef");
        System.out.println(s1.compareTo(s2));//-5
        System.out.println(s1.compareTo(s3));//7
    }
    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
    }
    public static void main1(String[] args) {
        //直接定义字符串
        String s1 = "hello";
        System.out.println(s1.length());
        System.out.println(s1.isEmpty());
        //创建对象调用构造方法定义字符串
        String s2 = new String("hello");
        System.out.println(s2);
        //利用字符数组来定义字符串
        char[] arr = new char[]{'h','e','l','l','o'};
        String s3 = new String(arr);
        System.out.println(s3);
    }
}
